using System;
using System.Collections.Generic;
using Matrix.Notification.Domain.Shared.Notifications;

namespace Matrix.Notification.Notifications
{
    /// <summary>
    /// 通知发送结果DTO
    /// </summary>
    public class NotificationResultDto
    {
        /// <summary>
        /// 通知ID
        /// </summary>
        public Guid NotificationId { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 外部ID
        /// </summary>
        public string? ExternalId { get; set; }

        /// <summary>
        /// 发送时间
        /// </summary>
        public DateTime SentTime { get; set; }

        /// <summary>
        /// 预估送达时间
        /// </summary>
        public DateTime? EstimatedDeliveryTime { get; set; }

        /// <summary>
        /// 失败原因
        /// </summary>
        public string? FailureReason { get; set; }

        /// <summary>
        /// 错误代码
        /// </summary>
        public string? ErrorCode { get; set; }

        /// <summary>
        /// 错误详情
        /// </summary>
        public string? ErrorDetails { get; set; }

        /// <summary>
        /// 是否需要重试
        /// </summary>
        public bool WillRetry { get; set; }

        /// <summary>
        /// 下次重试时间
        /// </summary>
        public DateTime? NextRetryTime { get; set; }

        /// <summary>
        /// 当前重试次数
        /// </summary>
        public int RetryCount { get; set; }

        /// <summary>
        /// 发送耗时（毫秒）
        /// </summary>
        public long SendTimeMs { get; set; }

        /// <summary>
        /// 通知渠道
        /// </summary>
        public NotificationChannel Channel { get; set; }

        /// <summary>
        /// 通知类型
        /// </summary>
        public NotificationType Type { get; set; }

        /// <summary>
        /// 通知优先级
        /// </summary>
        public NotificationPriority Priority { get; set; }

        /// <summary>
        /// 接收者信息
        /// </summary>
        public string? RecipientInfo { get; set; }

        /// <summary>
        /// 附加信息
        /// </summary>
        public Dictionary<string, object>? AdditionalData { get; set; }

        /// <summary>
        /// 状态码
        /// </summary>
        public string? StatusCode { get; set; }

        /// <summary>
        /// 状态消息
        /// </summary>
        public string? StatusMessage { get; set; }

        /// <summary>
        /// 服务提供商响应
        /// </summary>
        public string? ProviderResponse { get; set; }

        /// <summary>
        /// 跟踪ID
        /// </summary>
        public string? TrackingId { get; set; }
    }

    /// <summary>
    /// 批量通知发送结果DTO
    /// </summary>
    public class BatchNotificationResultDto
    {
        /// <summary>
        /// 批次ID
        /// </summary>
        public Guid BatchId { get; set; }

        /// <summary>
        /// 总数量
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 成功数量
        /// </summary>
        public int SuccessCount { get; set; }

        /// <summary>
        /// 失败数量
        /// </summary>
        public int FailureCount { get; set; }

        /// <summary>
        /// 跳过数量
        /// </summary>
        public int SkippedCount { get; set; }

        /// <summary>
        /// 批量发送时间
        /// </summary>
        public DateTime SentTime { get; set; }

        /// <summary>
        /// 总耗时（毫秒）
        /// </summary>
        public long TotalTimeMs { get; set; }

        /// <summary>
        /// 平均耗时（毫秒）
        /// </summary>
        public long AverageTimeMs { get; set; }

        /// <summary>
        /// 详细结果列表
        /// </summary>
        public List<NotificationResultDto>? Results { get; set; }

        /// <summary>
        /// 失败的通知列表
        /// </summary>
        public List<NotificationResultDto>? Failures { get; set; }

        /// <summary>
        /// 批次状态
        /// </summary>
        public BatchNotificationStatus Status { get; set; }

        /// <summary>
        /// 备注信息
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 统计信息
        /// </summary>
        public Dictionary<string, object>? Statistics { get; set; }
    }

    /// <summary>
    /// 批量通知状态枚举
    /// </summary>
    public enum BatchNotificationStatus
    {
        /// <summary>
        /// 处理中
        /// </summary>
        Processing = 0,

        /// <summary>
        /// 已完成
        /// </summary>
        Completed = 1,

        /// <summary>
        /// 部分失败
        /// </summary>
        PartiallyFailed = 2,

        /// <summary>
        /// 全部失败
        /// </summary>
        Failed = 3,

        /// <summary>
        /// 已取消
        /// </summary>
        Cancelled = 4
    }
}